package com.bkgy.modular.rawMaterialRules.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.modular.rawMaterialRules.entity.AcidRollingStockExamine;
import com.bkgy.modular.rawMaterialRules.mapper.AcidRollingStockExamineMapper;
import com.bkgy.modular.rawMaterialRules.service.AcidRollingStockExamineService;
import com.bkgy.sys.common.entity.ResultData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ZhuHongKai
 * @version 1.0
 * @ClassName AcidRollingStockExamineServiceImpl
 * @date 2023/1/4 16:35
 */
@Service
public class AcidRollingStockExamineServiceImpl extends ServiceImpl<AcidRollingStockExamineMapper, AcidRollingStockExamine> implements AcidRollingStockExamineService {
    @Resource
    private AcidRollingStockExamineMapper acidRollingStockExamineMapper;

    /**
     * 酸轧原料审核阈值配置数据查询
     * @return
     */
    @Override
    public ResultData findAcidRollingStockExamineData() {
        List<AcidRollingStockExamine> list = acidRollingStockExamineMapper.selectList(null);
        return ResultData.ResultDataFaultSelf("操作成功",list);
    }

    /**
     * 酸轧原料审核阈值配置数据更新
     * @param jsonObject
     * @return
     */
    @Override
    public ResultData updateAcidRollingStockExamineData(JSONObject jsonObject) {
        try {
            String dataId = jsonObject.getString("dataId");
            LambdaQueryWrapper<AcidRollingStockExamine> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(AcidRollingStockExamine::getGrade1,dataId);
            String data = jsonObject.getJSONObject("data").toJSONString();
            AcidRollingStockExamine AcidRollingStockExamine = JSON.parseObject(data,AcidRollingStockExamine.class);
            acidRollingStockExamineMapper.update(AcidRollingStockExamine,queryWrapper);
            return ResultData.ResultDataSuccessSelf("修改成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("修改失败，错误信息为" + e.getMessage(), null);
        }
    }
}
